package cn.wolfcode.wolf2w.business.controller;

import cn.wolfcode.wolf2w.api.domain.Answer;
import cn.wolfcode.wolf2w.common.core.domain.R;
import cn.wolfcode.wolf2w.common.security.annotation.InnerAuth;
import cn.wolfcode.wolf2w.business.query.AnswerQuery;
import cn.wolfcode.wolf2w.business.service.IAnswerService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 回答 Controller
 * 
 * @author 浪兎兎
 * @date 2025-06-07
 */
@Api(value = "热门区域", description = "回答模块")
@ApiResponses({
        @ApiResponse(code = 200, message = "成功"),
        @ApiResponse(code = 401, message = "未登录"),
        @ApiResponse(code = 403, message = "无权限"),
        @ApiResponse(code = 404, message = "接口未找到"),
        @ApiResponse(code = 500, message = "服务器内部异常"),
        @ApiResponse(code = 501, message = "业务异常"),
})
@RestController
@RequestMapping("answers")
public class AnswerController {
    @Autowired
    private IAnswerService answerService;
    /**
     * 回答详情
     */
    @GetMapping("/detail/{id}")
    @ApiOperation(value = "回答详情")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "回答id", name = "id", required = true, dataType = "Long", example = "1")
    })
    public R<Answer> detail(@PathVariable Long id) {
        Answer answer = answerService.getById(id);
        return R.ok(answer);
    }
    /**
     * 回答 列表
     */
    @GetMapping("/query")
    @ApiOperation(value = "查询回答列表")
    public R<IPage<Answer>> query(AnswerQuery qo) {
        IPage<Answer> page = answerService.queryPage(qo);
        return R.ok(page);
    }

    @PostMapping("/giveLikeAnswer/{id}")
    @ApiOperation(value = "点赞回答")
    public R<Long> giveLikeAnswer(@PathVariable Long id) {
        return R.ok(answerService.giveLikeAnswer(id));
    }




    /*****************************************对外暴露Fegin接口**********************************************/
    /**
     * Feign 接口
     */
    @GetMapping("/feign/list")
    public R<List<Answer>> feignList() {
        return R.ok(answerService.list());
    }
    @InnerAuth
    @GetMapping("/feign/{id}")
    public R<Answer> feignGet(@PathVariable Long id) {
        return R.ok(answerService.getById(id));
    }
}
